<template>
  <div style="width: 100%;height: 100%;background-color: #fff;">
      <echartVue :option="option"></echartVue>
  </div>
</template>
<script setup>
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

import { getdian } from '../request/api';
import echartVue from './echart.vue';
let option = ref({
  color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  legend: {
    show: false,
    icon: 'circle',
    textStyle: {
      color: '#fff'
    },
    itemStyle: {
      color: 'rgb(255, 0, 135)'
    },
    data: ['2']
  },
  grid: {
    left: '0%',
    right: '4%',
    bottom: '3%',
    height: '80px', //强制Swiper的高度(px)，当你的Swiper在隐藏状态下初始化时且切换方向为垂直才用得上。这个参数会使自适应失效。
    containLabel: true
  },
  xAxis: [
    {
      type: 'category',
      boundaryGap: false,
      data: [
        '0.00',
        '2.00',
        '4.00',
        '6.00',
        '8.00',
        '10.00',
        '12.00',
        '14.00',
        '16.00',
        '18.00',
        '20.00',
        '22.00',
        '24.00'
      ]
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: '2',
      type: 'line',
      stack: 'Total',
      smooth: true,
      lineStyle: {
        width: 3,
        color: 'rgb(255, 0, 135)'
      },
      showSymbol: false,
      areaStyle: {
        opacity: 0.8,
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: '#FF0040'
          },
          {
            offset: 1,
            color: '#00006A'
          }
        ])
      },
      emphasis: {
        focus: 'series'
      },
      data: [220, 402, 231, 134, 190, 230, 120]
    }
  ]
})
onMounted(() => {
  getdian().then((res) => {
    // console.log(res)
    let name = res.data.data.map((item, index) => {
      return item.category
    })
    let names = [...new Set(name)]
    option.value.legend.data = names
    option.value.series[0].name = names.toString()
    option.value.series[0].data = res.data.data.map((item) => item.value)
  })
})
</script>


<style  scoped lang='scss'>

.top_tu {
  width: 100%;
  height: 260px;
  margin-top: 20px;
  background: #0c1d5f;
  border: 1px solid blue;
}
</style>
